package com.shunwang.caipiao.vo;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

public class NumberIntervalVo {
	/** tageter number */
	private Integer source;
	/** average Interval */
	private float avg=0L;
	/** interval detail */
	private List<Integer> intervalDetail = new ArrayList<Integer>();
	/** 出现次数 */
	private Integer times=0;
	/** 未出现次数  */
	private Integer missTime=0;
	
	private Integer totalInterval = 0;
	
	public NumberIntervalVo(Integer targetNumber){
		this.source = targetNumber;
	}
	
	public boolean hasShowAvg(){
		if(times == 0 || totalInterval ==0 || getAvg() == 0){
			return false;
		}
		float show = avg - missTime;
		return show > -2 && show < 2;
	}
	
	public void intervalTimes(int intervalTimes){
		intervalDetail.add(intervalTimes);
		times++;
		totalInterval+=intervalTimes;
		missTime = 0;
	}
	
	public void IntervalTimes(){
		int interval = 0;
		if(missTime != 0){
			interval = missTime;
		}
		intervalTimes(interval);
	}
	
	public void missTimes(){
		missTime++;
	}

	public Integer getSource() {
		return source;
	}

	public float getAvg() {
		avg = new BigDecimal(totalInterval).divide(new BigDecimal(times),2,BigDecimal.ROUND_HALF_EVEN).floatValue();
		return avg;
	}

	public List<Integer> getIntervalDetail() {
		return intervalDetail;
	}

	public Integer getTimes() {
		return times;
	}

	public Integer getMissTime() {
		return missTime;
	}

	@Override
	public int hashCode() {
		return source.hashCode();
	}

	@Override
	public boolean equals(Object obj) {
		return source.equals(obj);
	}

	@Override
	public String toString() {
		return source.toString();
	}
	
}
